Date.prototype.Format = function (fmt) { //author: meizz
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
/**
 * 用户为登录
 */
if ($("#username_session").html() == "null") {
    $("#username_show").html("<a href=\"/news/login\">请登录</a>");
    $("#welcome_title").hide();
    $("#user_panel div div  h4").html("<a href=\"/news/login\">请登录</a>");
    $("#user_panel .panel-body div div h3").html("0");
    $("#logout_home").hide();
}
/**
 * 处理新闻json
 */
$.ajax({
    type: "POST",
    url: "/news/newslist",
    success: function (msg) {
        $.each(msg, function (index, obj) {
            var title = obj['newsitem'];
            var date = new Date(obj['newsdate']);
            var newsdate = date.Format("yyyy年MM月dd hh:mm:ss");
            $("#news_list").append("<li class=\"text-left\"><span class=\"right\">" + newsdate + "</span><a href=\"newsitem.jsp?newsid=\"><span class=\"fa fa-angle-right\">" + title + "</span> </a></li>");
            $("#hot_newslist").append("<li class=\"text-left\"><span class=\"right\">" + newsdate + "</span><a href=\"newsitem.jsp?newsid=\"><span class=\"fa fa-angle-right\">" + title + "</span> </a></li>");
            console.log(title + newsdate);
        });
    }
});
/**
 * 处理新闻类别
 */

$.ajax({
    type: "POST",
    url: "/news/news_category",
    success: function (msg) {
        $.each(msg, function (index, obj) {
            var title = obj['news_category_name'];
            $("#news_categorylist").append("<li class=\"active ripple\"><a class=\"tree-toggle nav-header\"><span class=\"fa-home fa\"></span>"+title+"<span class=\"fa-angle-right fa right-arrow text-right\"></span></a></li>");
        });
    }
});




